package com.ruoyi.system.service.impl;

import cn.hutool.core.util.StrUtil;
import com.ruoyi.system.domain.ExecuteLog;
import com.ruoyi.system.mapper.ExecuteLogMapper;
import com.ruoyi.system.service.ExecuteLogService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * 执行日志(ExecuteLog)表服务实现类
 *
 * @author stone
 * @since 2022-04-15 17:12:12
 */
@Service("executeLogService")
public class ExecuteLogServiceImpl implements ExecuteLogService {
    @Resource
    private ExecuteLogMapper executeLogMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public ExecuteLog queryById(Integer id) {
        return this.executeLogMapper.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param executeLog 筛选条件
     * @return 查询结果
     */
    @Override
    public List<ExecuteLog> page(ExecuteLog executeLog) {

        return this.executeLogMapper.queryAll(executeLog);

    }

    /**
     * 新增数据
     *
     * @param executeLog 实例对象
     * @return 实例对象
     */
    @Override
    public int insert(ExecuteLog executeLog) {
        return this.executeLogMapper.insert(executeLog);

    }

    /**
     * 修改数据
     *
     * @param executeLog 实例对象
     * @return 实例对象
     */
    @Override
    public int update(ExecuteLog executeLog) {
        return this.executeLogMapper.update(executeLog);
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public int deleteById(Integer id) {
        return this.executeLogMapper.deleteById(id);
    }


    @Override
    public int deleteByIds(String ids) {
        if (StrUtil.isBlank(ids)) {
            return 0;
        }
        Arrays.stream(ids.split(",")).map(Integer::parseInt).forEach(e -> this.executeLogMapper.deleteById(e));
        return 1;
    }
}
